package com.bdqn;

import com.bdqn.dao.StudentDao;
import com.bdqn.dao.StudentDaoMySQLImpl;
import com.bdqn.entity.Student;

import java.util.List;

public class Main {

    public static void main(String[] args) {

        // 测试查询
        testSelect();

        // 测试新增
        // testInsert();
    }

    /**
     * 测试查询
     */
    private static void testSelect() {

        // 实例化数据库操作对象
        StudentDao studentDao = new StudentDaoMySQLImpl();

        // 查询所有学生数据
        List<Student> students = studentDao.selectAll();

        // 循环打印学生信息
        for (Student student : students) {
            System.out.println(student);
        }

    }

    /**
     * 测试新增
     */
    private static void testInsert() {

        // 实例化数据库操作对象
        StudentDao studentDao = new StudentDaoMySQLImpl();

        // 创建学生对象用于保存
        Student student_zhangsan = new Student();
        student_zhangsan.setStudentNo(50001);
        student_zhangsan.setLoginPwd("123456");
        student_zhangsan.setStudentName("张三");
        student_zhangsan.setSex("男");
        student_zhangsan.setGradeID(2);

        // 调用接口插入学生数据
        int insert = studentDao.insert(student_zhangsan);

        // 根据执行结果进行提示
        if (insert >= 1) {
            System.out.println("数据插入成功！");
        } else {
            System.out.println("数据插入失败！");
        }
    }

}